<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/_sys/tcms_admin_web_page_wed_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/image/tcms_image_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/attachment/tcms_attachment_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/ci_attr_types/tcms_cia_nomenclature_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_attr_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/nomenclature/tcms_nomenclature_dbc.class.php');


abstract class CI_Type_Preview_WP extends TCMS_Admin_Web_Page_WED_UA {
	public function init() {
		parent::init();

		$v = $this->create_view();
		$this->add_view($v);

		$v2 = $this->create_view('not_exist');
		$this->add_view($v2);

		$ci_event = new Web_Event_Simple_Int('ci', Tangra_Parameter_Method::GET, 'ci');
		$this->wed->add_wed_event_action_pair($ci_event, 'ci_event', 20);
	}


	protected function default_event() {
		throw new Tangra_Module_Exception('Expecting "ci" parameter.');
	}


	protected function export_attachments(DB_Connection $dbc, $ci_id) {
		tangra_if_not_int_throw_e($ci_id);

		$ci_attachments = TCMS_CI_Attachment_DBC::load_ci_attachments($dbc, $ci_id);
		$attachments = array();
		foreach ($ci_attachments as  $ci) {
			$tmp = new TCMS_Attachment_DBC();
			if ($tmp->load_by_id($dbc, $ci->get_attachment())) {
				$attachments[] = clone $tmp;
			}
		}
		$this->export('attachments', $attachments);
	}


	protected function export_images(DB_Connection $dbc, $ci_id) {
		tangra_if_not_int_throw_e($ci_id);

		$ci_images = TCMS_CI_Image_DBC::load_ci_images($dbc, $ci_id);
		$images = array();
		foreach ($ci_images as  $cii) {
			$tmp = new TCMS_Image_DBC();
			if ($tmp->load_by_id($dbc, $cii->get_image())) {
				$images[] = clone $tmp;
			}
		}
		$this->export('images', $images);
	}
}